diff --git a/.babelrc.js b/.babelrc.js index 6685869..b5aa7cb 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -10,6 +10,7 @@ module.exports = { '@babel/plugin-proposal-do-expressions', '@babel/plugin-proposal-export-default-from', '@babel/plugin-proposal-function-bind', + 'macros', ], env: { diff --git a/build/shared.js b/build/shared.js index a83623e..a444e0e 100755 --- a/build/shared.js +++ b/build/shared.js @@ -95,7 +95,7 @@ const generateFileLoaderForImages = ({ publicPath }) => ({ // 大部分文件不应进行编码,因为可能降低页面加载性能 const generateUrlLoaderForImages = () => ({ test: input => reImageExt.test(input) && reBase64.test(input), - use: [ { + use: [ 'cache-loader', { loader: 'url-loader', options: { limit: 2048, diff --git a/build/webpack.config.js b/build/webpack.config.js index f6e30ae..0d398cc 100644 --- a/build/webpack.config.js +++ b/build/webpack.config.js @@ -1,4 +1,7 @@ module.exports = [ - require('./webpack.js.config'), + require('./webpack.js.config')('background', 'background-content-page'), + require('./webpack.js.config')('content', 'background-content-page'), + require('./webpack.js.config')('page', 'background-content-page'), + require('./webpack.js.config')('settings', 'settings'), require('./webpack.css.config'), ] diff --git a/build/webpack.css.config.js b/build/webpack.css.config.js index 86b051c..fab9a18 100644 --- a/build/webpack.css.config.js +++ b/build/webpack.css.config.js @@ -10,7 +10,7 @@ const { generateUrlLoaderForImages, } = require('./shared') -module.exports = (env, { mode } = defaultArgv) => ({ +module.exports = (_, { mode } = defaultArgv) => ({ name: 'css', entry: { diff --git a/build/webpack.js.config.js b/build/webpack.js.config.js index 5fc55a4..0af9ac0 100755 --- a/build/webpack.js.config.js +++ b/build/webpack.js.config.js @@ -11,12 +11,11 @@ const { generateFileLoaderForOtherAssets, } = require('./shared') -module.exports = (env, { mode } = defaultArgv) => ({ +module.exports = (id, entryFile) => (_, { mode } = defaultArgv) => ({ name: 'js', entry: { - 'background-content-page': approot('src/entries/background-content-page.js'), - 'settings': approot('src/entries/settings.js'), + [id]: approot(`src/entries/${entryFile}.js`), }, output: { @@ -28,7 +27,28 @@ module.exports = (env, { mode } = defaultArgv) => ({ module: { rules: [ - { test: /\.js$/, use: [ 'cache-loader', 'babel-loader' ] }, + { + test: /\.js$/, + use: [ + { + loader: 'cache-loader', + options: { + cacheIdentifier: require('cache-loader/package').version + mode + id, + }, + }, + 'babel-loader', + { + loader: 'ifdef-loader', + options: { + DEVELOPMENT: mode === 'development', + PRODUCTION: mode === 'production', + ENV_BACKGROUND: id === 'background', + ENV_CONTENT: id === 'content', + ENV_PAGE: id === 'page', + }, + }, + ], + }, generateStyleLoader({ mode }), generateUrlLoaderForImages(), generateFileLoaderForImages({ publicPath: `${EXTENSION_ORIGIN_PLACEHOLDER}/` }), diff --git a/package.json b/package.json index 2bd02ff..53ee689 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "babel-eslint": "^10.0.1", "babel-jest": "^24.7.1", "babel-loader": "^8.0.4", + "babel-plugin-macros": "^2.6.1", "cache-loader": "^4.0.0", "chalk": "^2.4.2", "copy-webpack-plugin": "^5.0.2", @@ -99,6 +100,8 @@ "eslint-plugin-react": "^7.12.4", "esm": "^3.2.22", "file-loader": "^4.0.0", + "ifdef-loader": "^2.1.4", + "import-all.macro": "^2.0.3", "jest": "^24.7.1", "jest-webpack-resolver": "^0.3.0", "less": "^3.9.0", diff --git a/src/background/feature/createFeatureClass.js b/src/background/feature/createFeatureClass.js index 5cee706..ec10992 100644 --- a/src/background/feature/createFeatureClass.js +++ b/src/background/feature/createFeatureClass.js @@ -23,10 +23,6 @@ export default ({ messaging, bridge, settings, modules }) => class Feature { } async init() { - if (!this.subfeatures.length) { - return - } - await this.loadOptionValues() await this.migrate() diff --git a/src/constants/envs.js b/src/constants/envs.js deleted file mode 100644 index ed554b6..0000000 --- a/src/constants/envs.js +++ /dev/null @@ -1,6 +0,0 @@ -// background script -export const ENV_BACKGROUND = 'background' -// 通过 manifest.json 指定的 content script -export const ENV_CONTENT = 'content' -// 由 content script 通过