Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO: 根据 opts.hash 自动处理这里的 filename
const commonsPlugins = (opts.commons || []).map(common => {
return new webpack.optimize.CommonsChunkPlugin(common);
});
// Declare outputPath here for reuse
const outputPath = opts.outputPath
? resolve(opts.cwd, opts.outputPath)
: resolve(opts.cwd, 'dist');
// Copy files in public to outputPath
const copyPlugins = opts.copy ? [new CopyWebpackPlugin(opts.copy)] : [];
if (existsSync(resolve(opts.cwd, 'public'))) {
copyPlugins.push(
new CopyWebpackPlugin(
[
{
from: resolve(opts.cwd, 'public'),
to: outputPath,
toType: 'dir',
},
],
{ ignore: ['**/.*'] },
),
);
}
// js 和 css 采用不同的 hash 算法
const jsHash = !isDev && opts.hash ? '.[chunkhash:8]' : '';
const cssHash = !isDev && opts.hash ? '.[contenthash:8]' : '';
scripts: {
test: /[\\/]src[\\/]scripts[\\/]/,
name: 'chunks/scripts',
chunks: 'all',
// 强制提取
enforce: true,
},
},
},
},
plugins: [
new WebpackBar({
profile: !isDev,
compiledIn: false,
}),
new CopyWebpackPlugin(copyCfgArr, {
context: resolve('src'),
}),
new ExtractTextPlugin('[name].wxss'),
new FriendlyErrorsWebpackPlugin(),
new BannerPlugin({
raw: true,
// 因为无法通过 html 的 script 标签插入
// 所以只好在入口文件 app.js 前插入公共依赖
banner: `require('./chunks/runtime');require('./chunks/vendors');require('./chunks/scripts');`,
include: 'app.js',
})
],
})
if (cco.module) {
module = {
...cco.module,
rules: [
...defaultRules,
...(cco.module.rules || [])
],
}
} else {
module = {
rules: defaultRules
}
}
const plugins = [
new CopyPlugin([
{
from: path.resolve(__dirname, "..", "..", 'mptemp'),
to: configure.outputFullpath
},
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': configure.dev ? '"development"' : '"production"',
}),
// react-native 全局可以使用的变量
new webpack.ProvidePlugin({
fetch: ['react-native', 'fetch'],
alert: ['react-native', 'alert'],
requestAnimationFrame: ['react-native', 'requestAnimationFrame'],
cancelAnimationFrame: ['react-native', 'cancelAnimationFrame'],
"_ARR": "@areslabs/regenerator-runtime"
const configFactory: webpack.ConfigurationFactory = (_, args) => {
const config = commonBuilder(__dirname, args.mode);
// Make all CSS/JS files appear at the /res location.
config.output!.publicPath = '/res/';
config.plugins!.push(
new CopyWebpackPlugin([
{ from: resolve(__dirname, 'build/canvaskit/canvaskit.wasm') },
{ from: resolve(__dirname, 'build/pathkit/pathkit.wasm') },
{ from: resolve(__dirname, 'node_modules/@webcomponents/custom-elements/custom-elements.min.js') },
]),
);
config.node = {
fs: 'empty',
};
return config;
};
const configFactory: webpack.ConfigurationFactory = (_, args) => {
// Don't minify the HTML since it contains Go template tags.
const config = commonBuilder(__dirname, args.mode, /* neverMinifyHtml= */ true);
config.output!.publicPath = '/static/';
config.plugins!.push(
new CopyWebpackPlugin([
{
from: resolve(__dirname, 'config.json'),
to: 'config.json',
},
]),
);
config.plugins!.push(
new HtmlWebpackInjectAttributesPlugin({
nonce: '{% .Nonce %}',
}),
);
config.resolve = config.resolve || {};
// https://github.com/webpack/node-libs-browser/issues/26#issuecomment-267954095
config.resolve.modules = [resolve(__dirname, '..', 'node_modules')];
POI_PUBLIC_PATH: JSON.stringify(api.config.publicPath),
POI_COMMAND: JSON.stringify(api.command),
__DEV__: JSON.stringify(api.command !== 'build')
},
api.config.constants
)
])
// Copy ./public/* to out dir
// In non-dev commands since it uses devServerOptions.contentBase instead
if (
api.options.command !== 'dev' &&
fs.existsSync(api.resolveBaseDir('public'))
) {
const CopyPlugin = require('copy-webpack-plugin')
CopyPlugin.__expression = `require('copy-webpack-plugin')`
api.chainWebpack(config => {
config.plugin('copy-public').use(CopyPlugin, [
[
{
from: api.resolveBaseDir('public'),
to: '.',
ignore: ['.DS_Store']
}
]
])
})
}
// Resolve loaders and modules in poi's node_modules folder
const inWorkspaces = __dirname.includes('/poi/packages/poi/')
}
const publicPath = (() => {
if (this.publicPath != null) {
return this.publicPath
} else if (compiler.options.output.publicPath != null) {
return compiler.options.output.publicPath
} else {
return ''
}
})()
const pluginsToApply = []
pluginsToApply.push(
new CopyWebpackPlugin(
this.assetsToCopy.map(({ path, cwpPatternConfig }) => ({
from: path,
to: `${this.outputPath}/${path}`,
...cwpPatternConfig,
})),
this.cwpOptions
)
)
const createAssetsPlugin = (assets, append) => {
if (assets.length) {
pluginsToApply.push(
new HtmlWebpackIncludeAssetsPlugin({
assets: assets.map(
asset =>
HtmlWebpackExternalsPlugin.URL_ENTRY.test(asset.path)
test: /\.css$/,
include: path.resolve(__dirname, 'src/css/options'),
use: extractOptions.extract(cssLoaders),
},
],
},
resolve: {
alias: {
config: path.resolve(__dirname, 'config/config.json'),
},
},
plugins: [
extractContent,
extractOptions,
new CleanWebpackPlugin([DIST_FOLDER]),
new CopyWebpackPlugin(staticFilesPath),
new GenerateJsonPlugin('manifest.json', getManifest(), null, 2),
IS_PRODUCTION
? new ZipPlugin({
path: path.resolve(__dirname, 'artifacts'),
filename: `dist-${env.browser}`,
})
: () => null,
],
};
};
loader: 'wxml-loader',
options: {
root: resolve('src'),
},
},
],
},
],
},
plugins: [
new EnvironmentPlugin({ NODE_ENV: 'development' }),
new DefinePlugin({ __DEV__: isDev }),
new WXAppWebpackPlugin({ clear: !isDev }),
new optimize.ModuleConcatenationPlugin(),
new CopyWebpackPlugin(copyConfig()),
!isDev && new MinifyPlugin(),
].filter(Boolean),
devtool: false,
resolve: {
modules: [resolve(__dirname, 'src'), 'node_modules'],
},
watchOptions: {
ignored: /build|manifest/,
aggregateTimeout: 300,
},
};
`.${platform.properties.type}.client.mjs`,
`.${platformName}.client.js`,
`.${platformName}.client.json`,
`.${platformName}.client.jsx`,
`.${platformName}.client.mjs`,
...(webpackConfig?.resolve?.extensions || [])
])
},
target: 'web',
plugins: [
...(webpackConfig.plugins || []),
new AssetsWebpackPlugin({
path: paths.dist,
filename: 'assets.json'
}),
new CopyWebpackPlugin([
{
from: path.resolve(paths.src, 'public'),
to: path.resolve(paths.dist)
}
]),
new IgnorePlugin(/^child_process$/),
new IgnorePlugin(/^deasync$/),
new IgnorePlugin(/^fs$/),
new IgnorePlugin(/^winston$/),
new HtmlWebpackPlugin({
title,
minify: true,
template: path.resolve(paths.platform, 'index.html')
}),
...(env !== 'production' ? [new NamedModulesPlugin()] : []),
...(action === 'start'